/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-09-20
 * Time: 12:15
 */
class Food {

}
class Fruit extends Food {

}
class Apple extends Fruit {

}
class Banana extends Fruit {

}
class Message2<T> { // 设置泛型
    private T message ;

    public T getMessage() {
        return message;
    }

    public void setMessage(T message) {
        this.message = message;
    }
}


public class Test2 {

    public static void main(String[] args) {
        Message2<Apple> message21 = new Message2<>();

        Message2<Banana> message22 = new Message2<>();

        Message2<Food> message23 = new Message2<>();


        Message2<Fruit> message24 = new Message2<>();
        func(message21);

        func(message22);

        //func(message23);  上界是fruit

        //func2(message23);
        func2(message24);
    }
    public static void func(Message2<? extends Fruit> message2) {
//        Apple apple=new Apple();
//        Fruit fruit2=apple;

        //Apple apple = message2.getMessage();
        Fruit fruit = message2.getMessage();

//        message2.setMessage(new Apple());
//        message2.setMessage(new Banana());
//        message2.setMessage(new Food());
//        message2.setMessage(new Fruit());
    }

    public static void func2(Message2<? super Fruit> message2) {
        message2.setMessage(new Apple());
        message2.setMessage(new Banana());

        Fruit fruit =(Fruit) message2.getMessage();
    }

}
